#ifndef OPERATIONS_MANAGEMENT_H
#define OPERATIONS_MANAGEMENT_H

#include <QWidget>
#include <QMessageBox>
#include <QTableWidgetItem>
#include <QPushButton>
#include <QDateTime>
#include "addticketdialog.h"

namespace Ui {
class operations_management;
}

class operations_management : public QWidget
{
    Q_OBJECT

public:
    explicit operations_management(QWidget *parent = nullptr);
    ~operations_management();

private slots:
    void onSearchButtonClicked();
    void onAddButtonClicked();
    void onDeleteButtonClicked();
    void onFirstPageClicked();
    void onPrevPageClicked();
    void onNextPageClicked();
    void onLastPageClicked();
    void onSaveAndRefreshClicked();
    void onTableItemDoubleClicked(int row, int column);
    void onCellChanged(int row, int column);
    void onTypeComboBoxChanged();

private:
    void setupConnections();
    void setupDatabase();
    void loadData();
    void loadPageData();
    void setupTable();
    void updatePageInfo();
    void clearTable();
    bool saveDataToDatabase();
    void refreshData();
    void fillTableData(const QJsonArray& tickets);
    QJsonObject buildSearchParams();
    QString getCurrentTicketType();
    QJsonObject buildTicketParams(const QString& ticketType = "");
    
    Ui::operations_management *ui;
    int currentPage;
    int totalPages;
    int pageSize;
    QString currentSearchText;
    QString currentSearchType;
};

#endif // OPERATIONS_MANAGEMENT_H
